<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item>首页</el-breadcrumb-item>
      <el-breadcrumb-item>私募管理</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <el-button size="mini" type="primary" @click="publish"
        >发布私募</el-button
      >

      <!-- 数据列表 -->
      <el-table :data="tableData" stripe border style="width: 100%">
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="id" label="ID" width="80"> </el-table-column>
        <el-table-column prop="projectName" label="项目名称"> </el-table-column>
        <el-table-column prop="coinName" label="币种名称"> </el-table-column>
        <el-table-column prop="privatePlacementPrice" label="私募单价(USDT)">
        </el-table-column>
        <el-table-column prop="privatePlacementNum" label="总私募额度">
        </el-table-column>
        <el-table-column prop="privatePlacementAlreadyNum" label="私募进度">
        </el-table-column>
        <el-table-column prop="smallUnit" label="最小数量"> </el-table-column>
        <el-table-column prop="createTime" label="创建时间"> </el-table-column>
        <el-table-column prop="type" label="状态">
          <template slot-scope="scope">
            <span v-if="scope.row.type">上架</span>
            <span v-else>下架</span>
          </template>
        </el-table-column>
        <el-table-column label="修改项目">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              icon="el-icon-edit"
              @click="changeCoin(scope.row)"
              >修改</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :page-sizes="[10, 20, 30]"
        :page-size="queryinfo.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination> -->
    </el-card>
    <!-- 发布私募-->
    <el-dialog title="发布私募" :visible.sync="dialogTableVisibleAddPrivate" @close="closeDialog">
      <el-row :gutter="20">
        <el-col :span="5">币种名称</el-col>
        <el-col :span="18">
          <el-select v-model="formList.coinId" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.tokenSEn"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">支付币种</el-col>
        <el-col :span="18">
          <el-select v-model="formList.privatePayCoinId" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.tokenSEn"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">项目名称</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.projectName"
            placeholder="请输入（必填）"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">私募总量</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.privatePlacementNum"
            placeholder="请输入（必填）"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">私募单价(USDT)</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.privatePlacementPrice"
            placeholder="请输入（必填）"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">最小认购单价(USDT)</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.smallUnit"
            placeholder="请输入（必填）"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">项目介绍</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.projectIntroduction"
            placeholder="请输入（必填）"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">发行总量</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.issuanceSum"
            placeholder="请输入（选填）"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">流通总量</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.ldSum"
            placeholder="请输入（选填）"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">发行时间</el-col>
        <el-col :span="18">
          <el-date-picker
            v-model="formList.issuanceTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="选择日期时间"
          >
          </el-date-picker>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">状态</el-col>
        <el-col :span="18">
          <el-switch
            v-model="formList.type"
            active-color="#13ce66"
            inactive-color="#ff4949"
          >
          </el-switch>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">私募状态</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.isComplete"
            placeholder="请输入（选填）1:进行中 2:已完成"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">备注</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.bz"
            placeholder="请输入（可选填）"
          ></el-input>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submit">确认发布</el-button>
      </span>
    </el-dialog>
    <!-- 修改项目-->
    <el-dialog title="修改" :visible.sync="dialogTableVisibleUpdatePrivate" @close="closeDialog">
      <el-row :gutter="20">
        <el-col :span="5">币种名称</el-col>
        <el-col :span="18">
          <el-select v-model="formList.coinId" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.tokenSEn"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">支付币种</el-col>
        <el-col :span="18">
          <el-select v-model="formList.privatePayCoinId" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.id"
              :label="item.tokenSEn"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">项目名称</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.projectName"
            placeholder="请输入（必填）"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">私募总量</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.privatePlacementNum"
            placeholder="请输入（必填）"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">私募单价(USDT)</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.privatePlacementPrice"
            placeholder="请输入（必填）"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">最小认购单价(USDT)</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.smallUnit"
            placeholder="请输入（必填）"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">项目介绍</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.projectIntroduction"
            placeholder="请输入（必填）"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">发行总量</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.issuanceSum"
            placeholder="请输入（选填）"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">流通总量</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.ldSum"
            placeholder="请输入（选填）"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">发行时间</el-col>
        <el-col :span="18">
          <el-date-picker
            v-model="formList.issuanceTime"
            value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime"
            placeholder="选择日期时间"
          >
          </el-date-picker>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">状态</el-col>
        <el-col :span="18">
          <el-switch
            v-model="formList.type"
            active-color="#13ce66"
            inactive-color="#ff4949"
          >
          </el-switch>
        </el-col>
      </el-row>
       <el-alert title="私募状态 (1:进行中 2:已完成)" type="success"> </el-alert>
      <el-row :gutter="20">
        <el-col :span="5">私募状态</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.isComplete"
          ></el-input>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="5">备注</el-col>
        <el-col :span="18">
          <el-input
            v-model="formList.bz"
            placeholder="请输入（可选填）"
          ></el-input>
        </el-col>
      </el-row>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updatePrivate">确认修改</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      formList: {
        coinId: "",
        privatePayCoinId: "",
        projectName: "",
        privatePlacementNum: "",
        privatePlacementPrice: "",
        smallUnit: "",
        projectIntroduction: "",
        issuanceSum: "",
        ldSum: "",
        issuanceTime: "",
        type: "",
        isComplete: "",
        bz:"",
      },
      queryinfo: {
        userTel: "",
        userEmail: "",
        pageIndex: 1,
        pageSize: 10,
      },
      total: 0,
      tableData: [],
      dialogTableVisibleUpdatePrivate: false,
      dialogTableVisibleAddPrivate: false,
      gridData: [],
      gridData1: [],
      options: [
        {
          value: "CNY",
          label: "CNY",
        },
        {
          value: "USDT",
          label: "USDT",
        },
      ],
    };
  },
  created() {
    this.getmsgList();
  },
  methods: {
    // 发布私募
    async publish(row) {
      this.dialogTableVisibleAddPrivate = true;
      this.getCoinListSm();
    },
    // 修改币信息
    async changeCoin(row) {
      this.dialogTableVisibleUpdatePrivate = true;
      this.getCoinListSm();
      this.formList.id =row.id
      this.formList.coinId =row.coinId
      this.formList.privatePayCoinId =row.privatePayCoinId
      this.formList.projectName =row.projectName
      this.formList.privatePlacementNum =row.privatePlacementNum
      this.formList.privatePlacementPrice =row.privatePlacementPrice
      this.formList.smallUnit =row.smallUnit
      this.formList.projectIntroduction =row.projectIntroduction
      this.formList.privatePlacementPrice =row.privatePlacementPrice
      this.formList.issuanceSum =row.issuanceSum
      this.formList.ldSum =row.ldSum
      this.formList.issuanceTime =row.issuanceTime
      this.formList.type =row.type
      this.formList.isComplete =row.isComplete
      this.formList.bz =row.bz
    },
    // 修改私募管理
    async updatePrivate() {
      const { data: res } = await this.$http.post(
        "currencyAudit/updatePrivate",
        this.httputil(this.formList)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.getmsgList();
      this.dialogTableVisibleUpdatePrivate = false;
    },
    // 发布私募管理
    async submit() {
      const { data: res } = await this.$http.post(
        "currencyAudit/addPrivate",
        this.httputil(this.formList)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.$message.success(res.msg);
      this.getmsgList();
      this.dialogTableVisibleAddPrivate = false;
    },
    // 获取收益记录列表
    async getmsgList() {
      const { data: res } = await this.$http.post(
        "currencyAudit/getPrivateList",
        this.httputil(this.queryinfo)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.tableData = res.data;
      this.total = res.data.count;
    },
    // 获取可以增加为私募的币种列表
    async getCoinListSm() {
      const { data: res } = await this.$http.post(
        "currencyAudit/getCoinListSm",
        this.httputil(this.queryinfo)
      );
      if (res.code !== 200) return this.$message.error(res.msg);
      this.options = res.data;
    },
    // 页面数量发生改变
    handleSizeChange(newSize) {
      this.queryinfo.pageSize = newSize;
      this.getmsgList();
    },
    // 页数发生改变
    handleCurrentChange(newCurrent) {
      this.queryinfo.pageIndex = newCurrent;
      this.getmsgList();
    },
    // 关闭对话框
     closeDialog() {
      this.formList.id = ""
      this.formList.coinId =""
      this.formList.privatePayCoinId =""
      this.formList.projectName =""
      this.formList.privatePlacementNum =""
      this.formList.privatePlacementPrice =""
      this.formList.smallUnit =""
      this.formList.projectIntroduction =""
      this.formList.privatePlacementPrice =""
      this.formList.issuanceSum =""
      this.formList.ldSum =""
      this.formList.issuanceTime =""
      this.formList.type =""
      this.formList.isComplete =""
      this.formList.bz =""
    },
  },
};
</script>
<style lang="less" scope>
.el-row {
  margin: 15px 0;
}
</style>
